<?php

   if($this->session->flashdata('msg'))
   {    echo '<div class="alert alert-success">
              <button type="button" class="close " data-dismiss="alert">&times;</button>
              <div class=alerta>';                
                echo "<p class='validacoes'>".$this->session->flashdata('msg');"</p>"; 
        echo "</div>
            </div>";     
    }   
        
         $id = 1;
        $this->load->model('ContaModel');
        $query = $this->ContaModel->getSaldo($id)->row();
        $saldo = number_format($query->saldo_acumulado,2,',','.');
         echo anchor(base_url(). "ContaController/chamarTelaCadastrarConta/".$id = NULL, 'Cadastrar na Raiz :: <span style="color:#000;">R$ '.$saldo.'</span>', array('title'=>'Cadastrar Conta','class'=>'btn btn-primary'));
      
?>

<div style="text-align: left; " id="hierarchy" >
    
    <?php
    
        $refs = array();
        $list = array();
      
      foreach ($contas as $conta)
      { $thisref = &$refs[ $conta['id_conta'] ];
        $thisref['id_conta_pai'] = $conta['id_conta_pai'];
        $thisref['descricao'] = $conta['descricao'];
        $thisref['id_conta'] = $conta['id_conta'];
        $thisref['saldo'] = $conta['saldo'];
        $thisref['saldo_acumulado'] = $conta['saldo_acumulado'];
      
        if ($conta['id_conta_pai'] == 1) 
        {	$list[ $conta['id_conta'] ] = &$thisref;
        } 
        else
        {  $refs[ $conta['id_conta_pai']]['children'][ $conta['id_conta']] = &$thisref;
        }     

      }
      echo toUL($list); 
      
      
    ?>
</div>         
